package edu.wong.pro.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import edu.wong.pro.iservice.IComment;

public class CommentAction extends ActionSupport{
	private IComment iComment;

	public IComment getiComment() {
		return iComment;
	}

	public void setiComment(IComment iComment) {
		this.iComment = iComment;
	}
	
	//发表评论
	public void relComment(){
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
		String newsId = request.getParameter("newsId");
		String comContent = request.getParameter("comContent");
		iComment.relComment(newsId, comContent);
	}
	
	//获取当前帖子的所有评论
	public void getAllComment() throws IOException{
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
		String newsId = request.getParameter("newsId");
		HttpServletResponse response = (HttpServletResponse) ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		writer.print(iComment.getAllComment(newsId));
		writer.flush();
		writer.close();	
	}
}
